/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.model.command.diagram;

import org.eclipse.gef.commands.Command;

public class SetAnchorHintsCommand extends Command {
	private String sourceRef, targetRef;
	private String oldSourceRef, oldTargetRef;

	public String getSourceHint() {
		return sourceRef;
	}

	public void setSourceHint(final String hint) {
		this.sourceRef = hint;
	}

	public String getTargetHint() {
		return targetRef;
	}

	public void setTargetHint(final String hint) {
		this.targetRef = hint;
	}

	@Override
	public void execute() {
		if (sourceRef != null) {
			oldSourceRef = (String) HintRegister.consumeHint("source");
			HintRegister.setHint("source", sourceRef);
		}
		if (targetRef != null) {
			oldTargetRef = (String) HintRegister.consumeHint("target");
			HintRegister.setHint("target", targetRef);
		}
	}

	@Override
	public void undo() {
		if (oldSourceRef == null)
			HintRegister.removeHint("source");
		else
			HintRegister.setHint("source", oldSourceRef);

		if (oldTargetRef == null)
			HintRegister.removeHint("target");
		else
			HintRegister.setHint("target", oldTargetRef);
	}

	@Override
	public void redo() {
		execute();
	}

	public void dispose() {
		sourceRef = null;
		targetRef = null;
	}
}
